package org.budo.beetl.function.druid.stat;

import com.alibaba.druid.support.http.stat.WebRequestStat;

/**
 * @author lmw
 */
public class DruidStatFunctionPackage {
    public String stat() {
        WebRequestStat requestStat = WebRequestStat.current();

        if (null == requestStat) {
            return "requestStat is null";
        }

        long dbTime = requestStat.getJdbcExecuteTimeNano() / 1000 / 1000;
        long urlTime = (System.currentTimeMillis() - requestStat.getStartMillis());
        long dbCount = requestStat.getJdbcExecuteCount();
        long dbFetch = requestStat.getJdbcFetchRowCount();

        return "<span title=\"" + "UrlTime=" + urlTime + ",DbTime=" + dbTime + ",DbCount=" + dbCount + ",DbFetch=" + dbFetch + "\">" //
                + "Time=" + urlTime + "," + dbTime + " Db=" + dbCount + "," + dbFetch + "</span>";
    }
}
